<script>
$(function() {
    $('.ajaxedit').editable('../update_noidung', {
         id        : 'data[Hinhanhdb][id]',
         name      : 'data[Hinhanhdb][hinhanh]',
         type      : 'text',
         cancel    : 'Hủy',
         submit    : 'Lưu',
         tooltip   : 'Click chọn để sửa'
    });
});
</script>

<div id="tabs">
	<ul>
        <li><?php echo $this->Html->link(__('Danh sách kênh', true), array('controller' => 'phankenhs', 'action' => 'xemkenhnv',$iddv,$nv_id)); ?> </li>
        <li id="current"><?php echo $this->Html->link(__('Công tác điểm bán', true), array('controller' => 'hinhanhdbs', 'action' => 'index',$kenh_id)); ?> </li>
        <li><?php echo $this->Html->link(__('Thông tin thị trường', true), array('controller' => 'thitruongkenhs', 'action' => 'index',$kenh_id)); ?> </li>
        <li><?php echo $this->Html->link(__('Tần suất chăm sóc', true), array('controller' => 'chamsockenhs', 'action' => 'index',$kenh_id)); ?> </li>
     </ul>  
</div>
<div class="index">
<h2><?php echo 'Kênh '.$kenhs[0]['kenhs']['tenkenh'].' - '.$kenhs[0]['kenhs']['diachi'];?></h2>
<div id="accordion">
	<h3 style=" padding:0 0 0em; margin:0;" ><a href="#">CÔNG TÁC ĐIỂM BÁN</a></h3>
	<div> 
		<table cellpadding="0" cellspacing="0" id="tables">
        	<tr>
        			<th><?php echo 'STT';?></th>
                    <th><?php echo 'Ngày lưu';?></th>
                    <?php foreach ($thongtindbs as $ktt => $vtt): //$ttin?>
							<th><?php echo $vtt?></th>                    		
                    <?php endforeach;   ?>
        			<th class="actions"><?php __('Lựa chọn');?></th>
        	</tr>
        	<?php
        	$i = 0;
        	$ngay = null;
        	foreach ($hinhanhdbs as $hinhanhdb):
        		if($ngay !=$hinhanhdb['Hinhanhdb']['ngaytao'])
        		{
        		$class = null;
        		if ($i++ % 2 == 0) {
        			$class = ' class="altrow"';
        		}
        		
        		$ngay = $hinhanhdb['Hinhanhdb']['ngaytao'];
        		
        		$idxoa = '';
        	?>
        	<tr<?php echo $class;?>>
        		<td><?php echo $i; ?>&nbsp;</td>
                <td><?php echo date('d-m-Y H:i:s',strtotime($hinhanhdb['Hinhanhdb']['ngaytao'])); ?>&nbsp;</td>
                <?php foreach ($thongtindbs as $ktt => $vtt): //$ttin?>
							<td>
							<?php
									foreach ($hinhanhdbs as $hinhs)
									{
										if($hinhs['Thongtindb']['id']==$ktt && $ngay==$hinhs['Hinhanhdb']['ngaytao'])
										{?>
										<div class='ajaxedit' id="<?php echo $hinhs['Hinhanhdb']['id'];?>"><?php echo $hinhs['Hinhanhdb']['noidung'];$idxoa .= '_'.$hinhs['Hinhanhdb']['id'];?></div>
							<?php }}?>
							</td>                    		
                 <?php endforeach;   ?>
        		
        		<td class="actions">
        			<?php echo $this->Html->link(__('Xóa', true), array('action' => 'delete', $idxoa,$hinhanhdb['Hinhanhdb']['kenh_id']), null, sprintf(__('Bạn muốn xóa thông tin này ?', true), $hinhanhdb['Hinhanhdb']['id'])); ?>
        		</td>
        	</tr>
        	<?php }//if so sanh ngay?>
        <?php endforeach; ?>
        	</table>
        	<p>
        	<?php
        	echo $this->Paginator->counter(array(
        	'format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)
        	));
        	?>	</p>
        
        	<div class="paging" style="background-color: #FCFDFD;">
        		<?php echo $this->Paginator->prev('<< ' . __('Trước', true), array(), null, array('class'=>'disabled'));?>
        	 | 	<?php echo $this->Paginator->numbers();?>
         |
        		<?php echo $this->Paginator->next(__('Sau', true) . ' >>', array(), null, array('class' => 'disabled'));?>
        	</div>
	</div>
	<h3 style=" padding:0 0 0em; margin:0;"><a href="#">CẬP NHẬT THÔNG TIN</a></h3>
	<div>
	<?php echo $this->Form->create('Hinhanhdb',array('url'=>'add/'.$kenh_id));?>
        	<fieldset>
        	<?php
        		echo $this->Form->hidden('kenh_id',array('value'=>$kenh_id));
        		foreach ($thongtindbs as $key => $value)
        		{
        			echo $this->Form->input($key,array('label'=>'Thông tin về '.$value,'name'=>'data[Hinhanhdb][thongtin]['.$key.']'));
        		}
        		echo $this->Form->hidden('ngaytao',array('value'=>date('Y-m-d H:i:s')));
        	?>
        	</fieldset>
        <?php echo $this->Form->end(__('Lưu', true));?>
	</div>
	
</div>
</div>
<script>
	$(function() {
		$( "#accordion" ).accordion();
	});
</script>